package com.itheima.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class CaptchaController {

    @RequestMapping(value = "/captcha", method = RequestMethod.GET)
    public void generateCaptcha(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String captchaText = CaptchaUtil.generateCaptchaText(4);
        HttpSession session = request.getSession();
        session.setAttribute("captcha", captchaText);
        CaptchaUtil.generateCaptchaImage(captchaText, response);
    }
}